﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace shopform
{
    public static class Validator
    {
        /// <summary>
        /// Checks if parameter string is alphanumeric.
        /// </summary>
        /// <param name="str">String to be verified.</param>
        /// <returns>True if str onyl contains 
        /// alphanum chars, otherwise false.</returns>
        public static bool IsAlphaNum(string str)
        {
            if (string.IsNullOrEmpty(str))
                return false;

            return (str.ToCharArray().All(c => Char.IsLetter(c) || Char.IsNumber(c)));
        }

        /// <summary>
        /// Checks if parameter string is alphanumeric with optional spaces.
        /// </summary>
        /// <param name="str">String to be verified.</param>
        /// <returns>True if str onyl contains 
        /// alphanum chars, otherwise false.</returns>
        public static bool IsAlphaNumOrSpace(string str)
        {
            if (string.IsNullOrEmpty(str))
                return false;

            return (str.ToCharArray().All(c => Char.IsLetter(c) || Char.IsNumber(c) || c == ' '));
        }

        /// <summary>
        /// Checks if parameter string is alpha char only.
        /// </summary>
        /// <param name="str">String to be verified.</param>
        /// <returns>True if str onyl contains 
        /// alpha chars, otherwise false.</returns>
        public static bool IsAlpha(string str)
        {
            if (string.IsNullOrEmpty(str))
                return false;

            return ( str.ToCharArray().All(c => Char.IsLetter(c)) );
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool isEmpty(String str)
        {
            if (str.Length == 0)
            {
                return true;
            }
            return false;
        }
    }
}
